package com.kgc.controller;

import com.kgc.util.RedisUtil;
import com.kgc.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class TestController {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Autowired
    private RedisUtil redisUtil;

    @GetMapping("demo3")
    public Object demo3(){
        //添加订单....MySQL数据库操作

        //添加订单倒计时30分钟
        redisUtil.set("10001","订单名称....",30*60);

        return new Result("true","Redis添加数据成功");
    }

    @GetMapping("demo2")
    public Object demo2(){
        //获取订单的剩余支付时间
        Long expire = redisTemplate.getExpire("10001");

        //MySQL数据库更新订单状态》失效

        return new Result(expire,"Redis获取数据成功");
    }

    @GetMapping("demo1")
    public Object demo1(){
        //添加订单....MySQL数据库操作

        //添加订单倒计时30分钟
        redisTemplate.opsForValue().set("10001","订单名称....",30L, TimeUnit.MINUTES);

        return new Result("true","Redis添加数据成功");
    }
}
